﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
 	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <div class="ibox-title" style="border-color: white;">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group form-inline">
                                <span>联系人姓名：</span>
                                <input id="name" type="text" placeholder="请输入联系人姓名" class="input-sm form-control">
                                <span>在岗状态：</span>
                                <select class="form-control"  id="status" name="status" >
									<option value="">==请选择==</option>
									<option value="1">==在岗==</option>
									<option value="2">==离岗==</option>
							    </select>
                                <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a> 
	                            <s:hasPermission name="company:addcontact">
	                            	<a  class="btn btn-sm btn-success" style="margin-left: 20px;" onclick="showadd();"> 添加</a>
	                            </s:hasPermission>
                             </div>
                        </div>
                    </div>
                </div>
                <!-- biaogebigin -->
                <div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;">
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
                <!-- tableover -->
            </div>
            <!-- PAGE CONTENT ENDS HERE -->

        </div>
        <!--/row-->
    </div>
    <!--/#page-content-->
</div>
<!--/.fluid-container#main-container-->
<script type="text/javascript">
    var company_id = "${companyId}";
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url: '<%=contextPath%>/company/contactListData',
            datatype: "json",
            postData: {'companyId':company_id}, //发送数据
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            mtype: "post",
            sortname: 'createDate',
            sortorder: "desc",
            rowNum: 15,
            rowList: [15, 30, 60],
            colNames: ["contactId","companyId","姓名","公司职位","联系电话","邮箱","微信","QQ", "创建人","创建时间","在岗状态","操作"],
            colModel: [{
                name: "contactId",
                index: "contactId",
                hidden: true
            },{
                name: "companyId",
                index: "companyId",
                hidden: true
            }, {
                name: "resume.trueName",
                index: "resume.trueName",
                width: 60,
                frozen : true
            }, {
                name: "position",
                index: "position",
                width: 60
            }, {
                name: "resume.cellphone",
                index: "resume.cellphone",
                width: 75,
                frozen : true
            }, {
                name: "resume.email",
                index: "resume.email",
                width: 60
            }, {
                name: "resume.wechat",
                index: "resume.wechat",
                width: 80
            }, {
                name: "resume.qq",
                index: "resume.qq",
                width: 60
            }, {
                name: "createUser.truename",
                index: "createUser.truename",
                width: 45
            }, {
                name: "createDate",
                index: "createDate",
                width: 80,
                editable:false,formatter:"date",formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'}
            }, {
                name: "status",
                index: "status",
                width: 65,
                formatter: function (value, options, row) {
                	var htm="";
                	if(value==1){
                		htm ="在岗";
                	}else if (value==2) {
                		htm ="离岗";
					}
                	return htm;
                }
            },  {
                formatter: function (cellvalue, options, row) {
                    return " <s:hasPermission name="company:editcontact"><a class='btn-sm btn-mini btn-warning' title='修改' onclick='showedit(&quot;" + row.contactId + "&quot;,&quot;" + row.companyId + "&quot;)'><i class='icon-edit'></i></a></s:hasPermission> "     
                           + " <s:hasPermission name="company:deletecontact"><a class='btn-sm btn-mini btn-danger' title='删除' onclick='del(&quot;" + row.contactId + "&quot;,&quot;" + row.companyId + "&quot;)'><i class='icon-trash'></i></a></s:hasPermission> ";
                },
                width: 100
            }],
            height: $(window).height() - 170,
            pager: "#pager_list",
            //multiselect: true,//多选按钮
            //multiboxonly: true,
            viewrecords: true,
            hidegrid: false
        });
        //表格自适应高宽
        $(window).bind("resize", function () {
            var b = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(b);
            $("#table_list").setGridHeight($(window).height() - 170);
        })
        $("#table_list").navGrid('#pager_list', {edit: false, add: false, del: false, search: false})
        /* 判断是否有添加权限 */
        //检索
        $("#find_btn").click(function () {
            var name = $("#name").val();
            var status = $("#status").val();
            $("#table_list").jqGrid('setGridParam', {
                postData: {'name': name,'status':status}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });

    //删除
    function del(id) {
    	swal({
    	    title: "您确定要删除该条记录吗",
    	    text: "删除后将无法恢复，请谨慎操作！",
    	    type: "warning",
    	    showCancelButton: true,
    	    confirmButtonColor: "#DD6B55",
    	    confirmButtonText: "删除",
    	    animation:"slide-from-bottom",
    	    cancelButtonText:"取消",
    	    closeOnConfirm: true
    	},function (){
    		 $.ajax({
    			 url:"<%=contextPath%>/company/deleteContact?companyId="+company_id+"&contactId="+id,
    			 dataType:'json',
    			 success:function(data){
    				if(data.code==200){
    					toastr.success("删除成功");
    					$("#table_list").trigger("reloadGrid");
    					
    		    	}else{
    		    		toastr.error("出现错误，请稍后再试！");
    		    	}
    			 },
    			error:function(){
    				toastr.error("未知错误，请稍后再试！");
    			}
    		 });
    	});
    };
    //查看
    function showeye(id) {
       window.open("<%=contextPath%>/company/detailView?id=" + id);
    }
    //修改
    function showedit(id) {
        openyem("修改联系人", "<%=contextPath%>/company/editContactView?contactId=" + id +"&companyId="+company_id, 600, 750);
    }
    
  //添加
    function showadd() {
        openyem("添加联系人", "<%=contextPath%>/company/addContactView?companyId="+company_id, 600, 750);
    }
</script>
</body>
</html>

